package org.study.base.exceptionhandler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.study.base.utils.BaseResult;

/**
 * @program: securityparent
 * @description:
 * @author: lishuang
 * @create: 2021-12-03 15:16
 **/

@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public BaseResult error(Exception e) {
        e.printStackTrace();
        return BaseResult.error().message("执行了全局异常处理..");
    }

    @ExceptionHandler(ArithmeticException.class)
    @ResponseBody
    public BaseResult error(ArithmeticException e) {
        e.printStackTrace();
        return BaseResult.error().message("执行了ArithmeticException异常处理..");
    }

    @ExceptionHandler(GuliException.class)
    @ResponseBody
    public BaseResult error(GuliException e) {
        log.error(e.getMessage());
        e.printStackTrace();

        return BaseResult.error().code(e.getCode()).message(e.getMsg());
    }

}